// shopMallPackage/components/orderItem/orderItem.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    orderData: {
      type: Object,
      value: {}
    },
    orderIndex: {
      type: Number,
      value: 0
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    //取消订单
    cancelOrder() {
      this.triggerEvent('cancelOrder', { orderData: this.properties.orderData, index: this.properties.orderIndex });
    },
    //删除订单
    deleteOrder() {
      this.triggerEvent('deleteOrder', { orderData: this.properties.orderData, index: this.properties.orderIndex });
    },
    // 申请退款:
    applyQuitAction() {
      this.triggerEvent('applyQuit', this.properties.orderData);
    },
    // 再次支付
    payAction() {
      this.triggerEvent("payAgain", this.properties.orderData);
    },
    // 确认收货
    sureOrder() {
      this.triggerEvent("sureOrder", { orderData: this.properties.orderData, index: this.properties.orderIndex })
    },
    // 查看物流信息
    seeLogAction() {
      this.triggerEvent("seeLog", this.properties.orderData)
    },
    //查看详情：
    seeOrderDetail() {
      //可以在这边直接操作的
      if (!this.properties.orderData.orderId) {
        wx.showToast({
          title: '订单号不存在',
          icon: "none"
        })
        return;
      }
      if (this.properties.orderData.refundStatus > 0) {
        wx.navigateTo({
          url: '/featurePackage/pages/order/refundOrderDetail/refundOrderDetail?orderId=' + this.properties.orderData.orderId,
        })
        return;
      }
      wx.navigateTo({
        url: '/featurePackage/pages/orderDetail/orderDetail?orderId=' + this.properties.orderData.orderId,
      })
    },
    // 查看退款原因：
    seeRejectReson() {
      wx.showModal({
        title: '退款原因',
        content: this.properties.orderData.refundReason || '暂无原因',
        confirmColor: "#FF0000",
        confirmText: "重新申请",
        cancelText: "知道了",
        success: res => {
          if (res.confirm) {
            this.triggerEvent('applyQuit', this.properties.orderData);
          }
        }
      })
    },
    copyOrderIdAction(e) {
      let id = e.currentTarget.dataset.id;
      wx.setClipboardData({
        data: id,
        success: function (res) {
          wx.getClipboardData({
            success: function (res) {
              wx.showToast({
                title: '复制订单号成功',
                icon: "none"
              })
            },
            fail: function (err) {
              wx.showToast({
                title: '复制失败',
                icon: "none"
              })
            }
          })
        }
      })

    },
  }
})
